<template>
  <div style="height: 6vh;background-color:#fff;padding: 10px 20px;">
    <span style="line-height:60px;font-size:20px;">顾客反馈信息管理</span>
    <el-button type="primary" style="float: right;margin-top: 10px;"
               @click="beforeAddMsg">新建信息</el-button>
  </div>
  <el-dialog
      :title="dialogTitle"
      style="width: 1000px;padding: 40px;"
      v-model="dialogVisible"
      :before-close="handleClose"
  >
    <el-form label-position="top" label-width="80px">
      <el-row :gutter="10">
        <el-col :span="12">
          <el-form-item label="反馈方式">
            <el-select placeholder="请选择" v-model="saveBackForm.feedbackWay">
              <el-option v-for="item in wayOptions"
                         :label="item.label" :value="item.value"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="联系方式">
            <el-input placeholder="请输入联系方式" v-model="saveBackForm.phone"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="10">
        <el-col :span="24">
          <el-form-item label="反馈内容">
            <el-input placeholder="请输入反馈内容" v-model="saveBackForm.message"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="10">
        <el-col :span="24">
          <el-form-item label="反馈原因">
            <el-input placeholder="请输入反馈原因" v-model="saveBackForm.reason"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="10">
        <el-col :span="12">
          <el-form-item label="反馈获得奖品">
            <el-input placeholder="请输入奖品" v-model="saveBackForm.prize"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="备注信息">
            <el-input placeholder="请输入备注信息" v-model="saveBackForm.remark"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="10">
        <el-form-item label="反馈地点">
          <el-select placeholder="请选择" v-model="saveBackForm.addr">
            <el-option v-for="item in addrOptions"
                       :label="item.label" :value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-col :span="12">
          <el-form-item label="反馈时间">
            <el-date-picker v-model="saveBackForm.feedbackTime" placeholder="请选择反馈时间"></el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <template #footer>
      <el-button @click="handleClose">取消</el-button>
      <el-button type="primary" @click="saveJob">保存</el-button>
    </template>
  </el-dialog>

  <!-- 用户搜索卡片 -->
  <el-card style="margin: 20px;height: 70px;">
    <el-form :inline="true">
<!--      <el-form-item label="反馈时间" style="width: 220px;">-->
<!--        <el-select placeholder="请选择" v-model="searchBackForm.feedbackTime" >-->
<!--          <el-option v-for="item in levelOptions"-->
<!--                     :label="item.label" :value="item.value"></el-option>-->
<!--        </el-select>-->
<!--      </el-form-item>-->
      <el-form-item label="反馈地点" style="width: 220px;">
        <el-select placeholder="请选择店铺" v-model="searchBackForm.addr" @change="loadBack">
          <el-option v-for="item in addrOptions"
                     :label="item.label" :value="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="反馈方式" style="width: 220px;">
        <el-select placeholder="请选择店铺" v-model="searchBackForm.feedbackWay" @change="loadBack">
          <el-option v-for="item in wayOptions"
                     :label="item.label" :value="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button @click="resetSearch">重置</el-button>
        <el-button type="primary" @click="loadBack">查询</el-button>
      </el-form-item>
    </el-form>
  </el-card>

  <!-- 用户表格卡片 -->
  <el-card style="margin: 20px;">
    <el-table :data="backArr">
      <el-table-column type="index" label="编号" width="80" align="center"></el-table-column>
      <el-table-column prop="phone" label="联系方式" align="center"></el-table-column>
      <el-table-column prop="message" label="反馈内容" align="center"></el-table-column>
      <el-table-column prop="reason" label="反馈原因" align="center"></el-table-column>
      <el-table-column prop="feedbackTime" label="反馈时间" align="center"></el-table-column>
      <el-table-column prop="addr" label="反馈地点" align="center"></el-table-column>
      <el-table-column prop="feedbackWay" label="反馈方式" align="center"
                       ></el-table-column>
      <el-table-column  prop="remark" label="备注信息" align="center"></el-table-column>
      <el-table-column label="操作" align="center">
        <template #default="scope">
          <el-button link type="primary" :disabled="scope.row.level==40"
                     @click="editJob(scope.row.id)">编辑</el-button>
          <el-button link type="primary" :disabled="scope.row.level==40"
                     @click="deleteJob(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </el-card>
</template>
<script setup>
import {onMounted, ref} from "vue";
import {ElMessage} from "element-plus";
import axios from "axios";
import qs from "qs";
import index from "vuex";

const dialogVisible = ref(false);
//定义变量用来控制弹窗的标题
const dialogTitle = ref('新建员工工作信息');

const saveBackForm = ref({
  feedbackTime:'',
  feedbackWay:'',
  phone:'',
  addr:'',
  message:'',
  reason:'',
  prize:'',
  remark:''

});
const searchBackForm=ref({
  // feedbackTime:'',
  feedbackWay:'',
  addr:''
})
const wayOptions=ref([{label:'线上',value:'线上'},{label:'线下',value:'线下'}])
const addrOptions=ref([{label:'万象城店',value:'万象城店'},{label:'上城国际店',value:'上城国际店'}])
const beforeAddMsg = ()=>{
  dialogVisible.value = true;
  dialogTitle.value = '新建信息';
}
// const titleFormatter=(row,column,cellValue,index)=>{
//   for (let item of levelOptions.value) {
//     if (item.value==cellValue) {
//       cellValue = item.label;
//     }
//   }
//   return cellValue;
// }

const saveJob = ()=>{
  let data = qs.stringify(saveBackForm.value);
  axios.post(BASE_URL+'/v1/back/save',data)
      .then((response)=>{
        if(response.data.code == 2000){
          ElMessage.success('保存成功!');
          dialogVisible.value = false;
          saveBackForm.value = {};
          loadBack();
        }else{
          ElMessage.error(response.data.msg);
        }
      })
}
const handleClose = ()=>{
  if(confirm('您确认要关闭本窗口吗?')){
    dialogVisible.value = false;
    saveBackForm.value = {};
  }
}
const backArr = ref([]);
const loadBack = ()=>{
  let data = qs.stringify(searchBackForm.value);
  axios.get(BASE_URL+'/v1/back/select?'+data)
      .then((response)=>{
        if(response.data.code == 2000){
          jobArr.value = response.data.data;
        }else{
          ElMessage.error(response.data.msg);
        }
      })
}
const resetSearch = ()=>{
  searchBackForm.value = {};
  loadBack();
}


// onMounted(()=>{
//   loadJob();
// })
const editJob = (id)=>{
  dialogVisible.value = true;
  dialogTitle.value = '编辑反馈信息';
  axios.get(BASE_URL+'/v1/back/select?id='+id).then((response)=>{
    if(response.data.code == 2000){
      saveBackForm.value = response.data.data[0];
    }else{
      ElMessage.error(response.data.msg);
    }
  })
}
// const changeStatus = (id,status)=>{
//   axios.post(BASE_URL+'/v1/job/update/status/'+id+'/'+status)
//       .then((response)=>{
//         if(response.data.code == 2000){
//           ElMessage.success('修改状态成功!');
//         }else{
//           ElMessage.error(response.data.msg);
//         }
//       })
// }
const deleteJob = (id)=>{
  if(confirm('您确认要删除该信息吗?')){
    axios.post(BASE_URL+'/v1/back/delete/'+id)
        .then((response)=>{
          if(response.data.code == 2000){
            ElMessage.success('删除成功!');
           loadBack();
          }else{
            ElMessage.error(response.data.msg);
          }
        })
  }
}
</script>


<style scoped>

</style>